home *** CD-ROM | disk | FTP | other *** search
- /* File: main.c */
-
- #define __Main__
- #include "ScriptScrap.h"
- #include "Prototypes.h"
-
- void Init_all(void)
- {
- Handle a_menu_bar;
- EventRecord one_null_event;
- short count;
- ProcessSerialNumber selfPSN = { 0, kCurrentProcess };
-
- InitGraf(&thePort); /* init Quickdraw and global variables*/
- InitFonts(); /* initialize Font manager */
- InitWindows(); /* init Window manager and setup WMgr GrafPort*/
- InitMenus();
- TEInit(); /* inititalize TextEdit */
- InitDialogs(NULL); /* initialize Dialog manager */
-
- FlushEvents(everyEvent, 0); /*clear the Event queue of all events */
-
- a_menu_bar = GetNewMBar(1001);
- SetMenuBar(a_menu_bar);
- AddResMenu(GetMHandle(kAppleMenu), 'DRVR');
- DrawMenuBar();
-
- gDone = FALSE; /* initialize flag to control Main Event Loop */
- InstallAppleEventHandlers();
-
- /* Set up the address descriptor used for sending Apple events to ourself */
- (void)AECreateDesc(typeProcessSerialNumber, (Ptr)&selfPSN, sizeof(selfPSN), &gSelfAddressDesc);
-
- /* Make sure we're the frontmost application when launched */
- for (count = 1; count <= 5; count++)
- WaitNextEvent(0, &one_null_event, 0, 0);
-
- gInFront = TRUE;
- InitCursor();
- }
-
-
- void DoKey (EventRecord *theEvent)
- {
- char keyPressed = (theEvent->message & charCodeMask);
-
- if (theEvent->modifiers & cmdKey) {
- AdjustMenus();
- Dispatch(MenuKey(keyPressed)); /*Command key down*/
- }
- } /* DoKey */
-
-
-
-
- void DoMouseDown (EventRecord *theEvent)
- {
- Point globalPt = theEvent->where;
- short windowPart;
- WindowPtr whichWindow;
- Rect dragRect;
-
- windowPart = FindWindow(globalPt, &whichWindow);
- switch (windowPart) {
- case inMenuBar:
- AdjustMenus();
- Dispatch(MenuSelect(globalPt));
- break;
-
- case inSysWindow:
- SystemClick(theEvent, whichWindow);
- break;
-
-
- case inGoAway:
- if (TrackGoAway(whichWindow, theEvent->where))
- CloseAWindow(whichWindow);
- break;
-
- case inDrag:
- dragRect = screenBits.bounds;
- dragRect.top = 40;
- DragWindow(whichWindow, theEvent->where, &dragRect);
- break;
-
- case inContent:
- DoContentClick(whichWindow, globalPt);
- break;
-
- }
- } /* DoMouseDown */
-
-
- void MainLoop(void)
- {
- EventRecord theEvent;
- DialogPtr whichDialog;
- short itemHit;
-
- while (!gDone) {
- WaitNextEvent(everyEvent, &theEvent, 120L, NULL);
- switch (theEvent.what) {
- case nullEvent:
- InitCursor();
- break;
-
- case mouseDown:
- DoMouseDown(&theEvent);
- break;
-
- case keyDown:
- case autoKey:
- DoKey(&theEvent);
- break;
-
- case activateEvt:
- DoActivate((WindowPtr)theEvent.message, theEvent.modifiers & 1);
- break;
-
- case updateEvt:
- DoUpdate((WindowPtr)theEvent.message);
- break;
-
- case osEvt:
- /* Handle "Suspend" and "Resume" events */
- if ((theEvent.message >> 24) == suspendResumeMessage) {
- gInFront = theEvent.modifiers & 1;
- if (FrontWindow())
- DoActivate(FrontWindow(), gInFront);
- }
- break;
-
- case kHighLevelEvent:
- (void)AEProcessAppleEvent(&theEvent);
- }
- }
- } /* MainEventLoop */
-
-
- void Shutdown()
- {
- /* We've been asked to quit, so close all open windows */
- WindowPeek currWindow;
- WindowPeek nextWindow;
-
- currWindow = (WindowPeek)FrontWindow();
- while (currWindow) {
- nextWindow = currWindow->nextWindow;
- CloseAWindow((WindowPtr)currWindow);
- currWindow = nextWindow;
- }
- }
-
-
- void main(void)
- {
- MaxApplZone();
- MoreMasters(); /* create more master pointers */
- MoreMasters(); /* create more master pointers */
- MoreMasters(); /* create more master pointers */
- MoreMasters(); /* create more master pointers */
-
- Init_all(); /* call initialization routine */
- AdjustMenus();
- MainLoop();
- Shutdown();
- }